<template>
  <div class="divBox relative">
    <el-card class="box-card">
      <div class="clearfix">
        <div class="container">
          <el-form label-width="100px" size="small">
            <!--<el-form-item label="订单类型：">-->
            <!--  <el-radio-group v-model="tableFrom.type" type="button" class="mr20" size="small" @change="seachList">-->
            <!--    <el-radio-button v-for="(item,i) in options" :key="i" :label="item.value">{{ item.label }}</el-radio-button>-->
            <!--  </el-radio-group>-->
            <!--</el-form-item>-->
            <el-form-item v-if="checkPermi(['admin:order:status:num'])" label="订单状态：">
              <el-radio-group v-model="tableFrom.status" type="button" @change="seachList">
                <el-radio-button label="all">全部 {{
                    '(' + orderChartType.all ? orderChartType.all : 0 + ')'
                  }}
                </el-radio-button>
                <el-radio-button label="unPaid">未支付 {{
                    '(' + orderChartType.unPaid ? orderChartType.unPaid : 0 + ')'
                  }}
                </el-radio-button>
                <el-radio-button label="notShipped">未发货
                  {{ '(' + orderChartType.notShipped ? orderChartType.notShipped : 0 + ')' }}
                </el-radio-button>
                <el-radio-button label="spike">待收货 {{
                    '(' + orderChartType.spike ? orderChartType.spike : 0 + ')'
                  }}
                </el-radio-button>
                <el-radio-button label="bargain">待评价
                  {{ '(' + orderChartType.bargain ? orderChartType.bargain : 0 + ')' }}
                </el-radio-button>
                <el-radio-button label="complete">交易完成
                  {{ '(' + orderChartType.complete ? orderChartType.complete : 0 + ')' }}
                </el-radio-button>
                <el-radio-button label="toBeWrittenOff">待核销
                  {{ '(' + orderChartType.toBeWrittenOff ? orderChartType.toBeWrittenOff : 0 + ')' }}
                </el-radio-button>
                <el-radio-button label="refunding">退款中
                  {{ '(' + orderChartType.refunding ? orderChartType.refunding : 0 + ')' }}
                </el-radio-button>
                <el-radio-button label="refunded">已退款
                  {{ '(' + orderChartType.refunded ? orderChartType.refunded : 0 + ')' }}
                </el-radio-button>
                <el-radio-button label="deleted">已删除
                  {{ '(' + orderChartType.deleted ? orderChartType.deleted : 0 + ')' }}
                </el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item class="width100" label="时间选择：">
              <el-radio-group v-model="tableFrom.dateLimit" class="mr20" size="small" type="button"
                              @change="selectChange(tableFrom.dateLimit)"
              >
                <el-radio-button v-for="(item,i) in fromList.fromTxt" :key="i" :label="item.val">{{
                    item.text
                  }}
                </el-radio-button>
              </el-radio-group>
              <el-date-picker v-model="timeVal" format="yyyy-MM-dd" placeholder="自定义时间" placement="bottom-end"
                              size="small" style="width: 220px;" type="daterange" value-format="yyyy-MM-dd"
                              @change="onchangeTime"
              />
            </el-form-item>
            <!-- <el-form-item label="订单类型：" class="width100">
              <el-select v-model="tableFrom.type" clearable placeholder="请选择" class="selWidth" @change="seachList">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item> -->
            <el-form-item class="width100" label="订单号：">
              <el-input v-model="tableFrom.orderNo" class="selWidth" clearable placeholder="请输入订单号" size="small">
                <el-button slot="append" icon="el-icon-search" size="small" @click="seachList"/>
              </el-input>
              <el-button v-hasPermi="['admin:export:excel:order']" size="small" @click="exports" style="margin-left: 15px">导出</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-card>
    <div class="mt20">
      <!-- <cards-data :cardLists="cardLists" v-if="checkPermi(['admin:order:list:data'])"></cards-data> -->
    </div>
    <el-card class="box-card" style="padding-bottom: 20px">
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        :header-cell-style=" {fontWeight:'bold'}"
        :row-key="(row)=>{ return row.id}"
        class="table"
        highlight-current-row
        size="mini"
      >
        <!-- @selection-change="handleSelectionChange" -->
        <!-- <el-table-column
          type="selection"
          :reserve-selection="true"
          width="55"
        /> -->
        <el-table-column
          v-if="checkedCities.includes('订单号')"
          label="订单号"
          min-width="140"
        >
          <template slot-scope="scope">
            <span style="display: block;" v-text="scope.row.snkey"/>
            <span v-show="scope.row.isDel" style="color: #ED4014;display: block;">用户已删除</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="checkedCities.includes('订单类型')"
          align="center"
          label="订单类型" min-width="110"
          prop="marketType"
        />
        <el-table-column
          v-if="checkedCities.includes('商品信息')"
          label="商品图" width="60"
        >
          <template slot-scope="scope">
            <div v-if=" scope.row.itemsList && scope.row.itemsList.length" slot="reference">
              <div v-for="(val, i ) in scope.row.itemsList" :key="i" class="tabBox acea-row row-middle"
                   style="flex-wrap: inherit;"
              >
                <div class="demo-image__preview mr10" style="display: flex; align-items: center; margin: 5px 0">
                  <el-image
                    :preview-src-list="[val.cover]"
                    :src="val.cover"
                  />
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          v-if="checkedCities.includes('商品信息')"
          label="商品信息"
          min-width="400"
        >
          <template slot-scope="scope">
            <el-popover :open-delay="800" placement="top" trigger="hover">
              <div v-if=" scope.row.itemsList && scope.row.itemsList.length" slot="reference">
                <div v-for="(val, i ) in scope.row.itemsList" :key="i" class="tabBox acea-row row-middle"
                     style="flex-wrap: inherit;"
                >
                  <!--<div class="demo-image__preview mr10">-->
                  <!--  <el-image-->
                  <!--    :preview-src-list="[val.cover]"-->
                  <!--    :src="val.cover"-->
                  <!--  />-->
                  <!--</div>-->
                  <div class="text_overflow" style="line-height: 40px">
                    <span class="tabBox_tit mr10">{{ val.title }}</span>
                    <span class="tabBox_pice ">{{ '¥' + val.lowPrice + ' x ' + val.quantity }}</span>
                  </div>
                </div>
              </div>
              <div v-if=" scope.row.itemsList && scope.row.itemsList.length" class="pup_card">
                <div v-for="(val, i ) in scope.row.itemsList" :key="i" class="tabBox acea-row row-middle"
                     style="flex-wrap: inherit;"
                >
                  <div class="">
                    <span class="tabBox_tit mr10">{{ val.title }}</span>
                    <span class="tabBox_pice">{{ '¥' + val.lowPrice + ' x ' + val.quantity }}</span>
                  </div>
                </div>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column
          v-if="checkedCities.includes('订单金额')"
          align="center"
          label="订单金额" min-width="80"
          prop="totalMoney"
        />
        <!-- <el-table-column
          label="支付方式"
          min-width="80"
          v-if="checkedCities.includes('支付方式')"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.payTypeStr }}</span>
          </template>
        </el-table-column> -->
        <el-table-column
          v-if="checkedCities.includes('订单状态')"
          align="center"
          label="订单状态" min-width="100"
        >
          <template slot-scope="scope">
            <div>
              <div v-if="scope.row.refundStatus !=='无'" class="refunding">
                <template>
                  <el-popover :open-delay="500" placement="top" trigger="hover">
                    <b slot="reference" style="color: #f124c7;cursor:pointer;">{{ scope.row.refundStatus }}</b>
                    <div class="pup_card flex-column">
                      <span>退款原因：{{ scope.row.refundReason }}</span>
                      <span>备注说明：{{ scope.row.refundExplain }}</span>
                      <span>退款时间：{{ scope.row.refundTime }}</span>
                      <span class="acea-row">
                            退款凭证：
                            <template v-if="scope.row.refundImages">
                              <div v-for="(item, index) in scope.row.refundImages.split(',')" :key="index"
                                   class="demo-image__preview" style="width: 35px;height: auto;display: inline-block;"
                              >
                              <el-image
                                :preview-src-list="[item]"
                                :src="item"
                              />
                            </div>
                            </template>
                            <span v-else style="display: inline-block">无</span>
                          </span>
                    </div>
                  </el-popover>
                </template>
              </div>
              <span v-else>{{ scope.row.status }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          v-if="checkedCities.includes('收货人/手机')"
          align="center"
          label="收货人/手机"
          min-width="160" prop="username"
        >
          <template slot-scope="scope">
            <div style="display: flex; justify-content: space-evenly">
              <div v-if="scope.row.username" style="margin-left: 20px">{{ scope.row.username }}</div>
              <div v-if="scope.row.phone" style="margin-right: 20px">
                <el-popover :open-delay="500" placement="bottom" trigger="hover">
                  <b slot="reference" style="cursor:pointer;">
                    {{ scope.row.phone.substring(0, 4) + '****' + scope.row.phone.substring(7) }}
                  </b>
                  手机：{{ scope.row.phone }}
                </el-popover>
              </div>
              <div v-if="!scope.row.username && !scope.row.phone">-</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          v-if="checkedCities.includes('下单时间')"
          align="center"
          label="下单时间"
          min-width="150" prop="createdTime"
        />
        <el-table-column :render-header="renderHeader" align="center" fixed="right" label="操作" min-width="150">
          <template slot-scope="scope">
            <el-button v-if="scope.row.paid === false" v-hasPermi="['admin:order:update:price']" class="mr10"
                       size="small" type="text"
                       @click="edit(scope.row)"
            >改价
            </el-button>
            <el-button
              v-if="!scope.row.offline && scope.row.paid && scope.row.refundStatus =='无' && scope.row.status=='已支付'"
              v-hasPermi="['admin:order:send']" class="mr10" size="small" type="text" @click="sendOrder(scope.row)"
            >发送货
            </el-button>
            <!-- <el-button v-if=" scope.row.offline && scope.row.paid  && scope.row.refundStatus == '无' && scope.row.status=='已支付'" type="text" size="small" class="mr10" v-hasPermi="['admin:order:write:update']" @click="onWriteOff(scope.row)">立即核销</el-button> -->
            <el-dropdown trigger="click">
              <span class="el-dropdown-link">
                更多<i class="el-icon-arrow-down el-icon--right"/>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-if="checkPermi(['admin:order:info'])" @click.native="onOrderDetails(scope.row.id)">
                  订单详情
                </el-dropdown-item>
                <el-dropdown-item v-if="checkPermi(['admin:order:status:list'])"
                                  @click.native="onOrderLog(scope.row.id)"
                >订单记录
                </el-dropdown-item>
                <el-dropdown-item v-if="checkPermi(['admin:order:mark'])" @click.native="onOrderMark(scope.row)">
                  订单备注
                </el-dropdown-item>
                <el-dropdown-item
                  v-if="scope.row.refundStatus == '申请退款中' && checkPermi(['admin:order:refund:refuse'])"
                  @click.native="onOrderRefuse(scope.row)"
                >拒绝退款
                </el-dropdown-item>
                <!--v-show="((scope.row.statusStr.key !== 'refunded' && scope.row.statusStr.key !== 'unPaid') && (parseFloat(scope.row.payPrice) >= parseFloat(scope.row.refundPrice))) || (scope.row.payPrice == 0 && [0,1].indexOf(scope.row.refundStatus) !== -1)"-->
                <el-dropdown-item v-if="scope.row.refundStatus == '申请退款中' && checkPermi(['admin:order:refund'])"
                                  @click.native="onOrderRefund(scope.row)"
                >立即退款
                </el-dropdown-item>
                <el-dropdown-item v-if="scope.row.key === 'deleted' && checkPermi(['admin:order:delete'])"
                                  @click.native="handleDelete(scope.row, scope.$index)"
                >删除订单
                </el-dropdown-item>
                <!-- <el-dropdown-item v-if="scope.row.key !== 'unPaid'" @click.native="onOrderPrint(scope.row)" >打印小票</el-dropdown-item> -->
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <el-col align="right">
        <el-pagination
          :current-page="tableFrom.page"
          :page-size="tableFrom.limit"
          :page-sizes="[10, 20, 40, 100]"
          :total="tableData.total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </el-col>
    </el-card>
    <div v-show="card_select_show" class="card_abs">
      <template>
        <div class="cell_ht">
          <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选
          </el-checkbox>
          <el-button type="text" @click="checkSave()">保存</el-button>
        </div>
        <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
          <el-checkbox v-for="item in columnData" :key="item" :label="item" class="check_cell">{{ item }}</el-checkbox>
        </el-checkbox-group>
      </template>
    </div>
    <!--编辑-->
    <el-dialog
      :before-close="handleClose"
      :visible.sync="dialogVisible"
      title="编辑订单"
      width="500px"
    >
      <zb-parser
        v-if="dialogVisible"
        :edit-data="editData"
        :form-id="104"
        :is-create="isCreate"
        @resetForm="resetForm"
        @submit="handlerSubmit"
      />
    </el-dialog>

    <!--记录-->
    <el-dialog
      :visible.sync="dialogVisibleJI"
      title="操作记录"
      width="700px"
    >
      <el-table
        v-loading="LogLoading"
        :data="tableDataLog.data"
        border
        style="width: 100%"
      >
        <el-table-column
          align="center"
          label="ID"
          min-width="80"
          prop="oid"
        />
        <el-table-column
          align="center"
          label="操作记录"
          min-width="280"
          prop="changeMessage"
        />
        <el-table-column
          align="center"
          label="操作时间"
          min-width="280"
          prop="createTime"
        />
      </el-table>
      <div style="overflow: hidden">
        <el-col align="right">
          <el-pagination
            :current-page="tableFromLog.page"
            :page-size="tableFromLog.limit"
            :page-sizes="[10, 20, 30, 40]"
            :total="tableDataLog.total"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChangeLog"
            @current-change="pageChangeLog"
          />
        </el-col>
      </div>
    </el-dialog>

    <!--详情-->
    <details-from ref="orderDetail" :orderId="orderId"/>

    <!-- 发送货 -->
    <order-send ref="send" :orderId="orderId" @submitFail="getList"></order-send>

    <!-- 发送货视频号商品 -->
    <order-video-send ref="videoSend" :orderId="orderId" @submitFail="getList"></order-video-send>

    <!--拒绝退款-->
    <el-dialog
      v-if="RefuseVisible"
      :before-close="RefusehandleClose"
      :visible.sync="RefuseVisible"
      title="拒绝退款原因"
      width="500px"
    >
      <zb-parser
        :edit-data="RefuseData"
        :form-id="106"
        :is-create="1"
        @resetForm="resetFormRefusehand"
        @submit="RefusehandlerSubmit"
      />
    </el-dialog>

    <!--立即退款-->
    <el-dialog
      :before-close="refundhandleClose"
      :visible.sync="refundVisible"
      title="退款处理"
      width="500px"
    >
      <zb-parser
        v-if="refundVisible"
        :edit-data="refundData"
        :form-id="107"
        :is-create="1"
        @resetForm="resetFormRefundhandler"
        @submit="refundhandlerSubmit"
      />
    </el-dialog>
  </div>
</template>

<script>
import {
  orderDeleteApi,
  orderListApi,
  orderListDataApi,
  orderLogApi,
  orderMarkApi,
  orderPrint,
  orderRefundApi,
  orderRefuseApi,
  orderStatusNumApi,
  updatePriceApi,
  writeUpdateApi
} from '@/api/order'
import cardsData from '@/components/cards/index'
import zbParser from '@/components/FormGenerator/components/parser/ZBParser'
import detailsFrom from './orderDetail'
import orderSend from './orderSend'
import orderVideoSend from './orderVideoSend'
import { isWriteOff } from '@/utils'
import { orderExcelApi } from '@/api/store'
import { checkPermi } from '@/utils/permission' // 权限判断函数
export default {
  name: 'orderlistDetails',
  components: {
    cardsData,
    zbParser,
    detailsFrom,
    orderSend,
    orderVideoSend
  },
  data() {
    return {
      options: [
        {
          value: 0,
          label: '全部'
        }, {
          value: 2,
          label: '商城订单'
        }, {
          value: 1,
          label: '视频号订单'
        }],
      RefuseVisible: false,
      RefuseData: {},
      orderId: 0,
      refundVisible: false,
      refundData: {},
      dialogVisibleJI: false,
      tableDataLog: {
        data: [],
        total: 0
      },
      tableFromLog: {
        page: 1,
        limit: 10,
        orderNo: 0
      },
      LogLoading: false,
      isCreate: 1,
      editData: null,
      dialogVisible: false,
      tableData: {
        data: [],
        total: 0
      },
      listLoading: true,
      tableFrom: {
        status: 'all',
        dateLimit: '',
        orderNo: '',
        page: 1,
        limit: 10,
        type: 0
      },
      orderChartType: {},
      timeVal: [],
      fromList: this.$constants.fromList,
      fromType: [
        { value: 'all', text: '全部' },
        { value: 'info', text: '普通' },
        { value: 'pintuan', text: '拼团' },
        { value: 'bragin', text: '砍价' },
        { value: 'miaosha', text: '秒杀' }
      ],
      selectionList: [],
      ids: '',
      orderids: '',
      cardLists: [],
      isWriteOff: isWriteOff(),
      proType: 0,
      active: false,
      card_select_show: false,
      checkAll: false,
      checkedCities: ['订单号', '订单类型', '商品信息', '订单金额', '支付方式', '订单状态', '收货人/手机', '下单时间'],
      columnData: ['订单号', '订单类型', '商品信息', '订单金额', '支付方式', '订单状态', '收货人/手机', '下单时间'],
      isIndeterminate: true
    }
  },
  created() {
    if (window.location.search.split('=')[1]) {
      console.log('window.location.search.split', (window.location.search.split('=')[1]))
      this.tableFrom.status = (window.location.search.split('=')[1])
    }
  },
  mounted() {
    this.getList()
    this.getOrderStatusNum()
    // this.getOrderListData();
  },
  methods: {
    checkPermi,
    resetFormRefundhandler() {
      this.refundVisible = false
    },
    resetFormRefusehand() {
      this.RefuseVisible = false
    },
    resetForm(formValue) {
      this.dialogVisible = false
    },
    // 核销订单
    onWriteOff(row) {
      this.$modalSure('核销订单吗').then(() => {
        writeUpdateApi(row.verifyCode).then(() => {
          this.$message.success('核销成功')
          this.tableFrom.page = 1
          this.getList()
        })
      })
    },
    seachList() {
      this.tableFrom.page = 1
      this.getList()
      this.getOrderStatusNum()
    },
    // 拒绝退款
    RefusehandleClose() {
      this.RefuseVisible = false
    },
    onOrderRefuse(row) {
      this.orderids = row.id
      this.RefuseData = {
        snkey: row.snkey,
        orderId: row.id,
        reason: ''
      }
      this.RefuseVisible = true
    },
    RefusehandlerSubmit(formValue) {
      orderRefuseApi({ orderNo: this.orderids, reason: formValue.reason }).then(data => {
        this.$message.success('操作成功')
        this.RefuseVisible = false
        this.getList()
      })
    },
    // 立即退款
    refundhandleClose() {
      this.refundVisible = false
    },
    onOrderRefund(row) {
      this.refundData = {
        snkey: row.snkey,
        orderId: row.id,
        amount: row.totalMoney,
        type: ''
      }
      this.orderids = row.id
      this.refundVisible = true
    },
    refundhandlerSubmit(formValue) {
      orderRefundApi({ amount: formValue.amount, orderNo: this.orderids }).then(data => {
        this.$message.success('操作成功')
        this.refundVisible = false
        this.getList()
      })
    },
    // 发送
    sendOrder(row) {
      // if(row.type===0){
      this.$refs.send.modals = true
      this.$refs.send.getList()
      // this.$refs.send.sheetInfo();
      // }else{
      //   this.$refs.videoSend.modals = true;
      //   if(!JSON.parse(sessionStorage.getItem('videoExpress'))) this.$refs.videoSend.companyGetList();
      // }
      this.orderId = row.id
    },
    // 订单删除
    handleDelete(row, idx) {
      if (row.isDel) {
        this.$modalSure().then(() => {
          orderDeleteApi({ orderNo: row.id }).then(() => {
            this.$message.success('删除成功')
            this.tableData.data.splice(idx, 1)
          })
        })
      } else {
        this.$confirm('您选择的的订单存在用户未删除的订单，无法删除用户未删除的订单！', '提示', {
          confirmButtonText: '确定',
          type: 'error'
        })
      }
    },
    // 详情
    onOrderDetails(id) {
      this.orderId = id
      this.$refs.orderDetail.getDetail(id)
      this.$refs.orderDetail.dialogVisible = true
    },
    // 订单记录
    onOrderLog(id) {
      this.dialogVisibleJI = true
      this.LogLoading = true
      this.tableFromLog.orderNo = id
      orderLogApi(this.tableFromLog).then(res => {
        this.tableDataLog.data = res.records
        this.tableDataLog.total = res.total
        this.LogLoading = false
      }).catch(() => {
        this.LogLoading = false
      })
    },
    pageChangeLog(page) {
      this.tableFromLog.page = page
      this.onOrderLog()
    },
    handleSizeChangeLog(val) {
      this.tableFromLog.limit = val
      this.onOrderLog()
    },
    handleClose() {
      this.dialogVisible = false
    },
    // 备注
    onOrderMark(row) {
      this.$prompt('订单备注', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputErrorMessage: '请输入订单备注',
        inputType: 'textarea',
        inputValue: row.note,
        inputPlaceholder: '请输入订单备注',
        inputValidator: (value) => {
          if (!value) return '输入不能为空'
        }
      }).then(({ value }) => {
        orderMarkApi({ mark: value, orderNo: row.id }).then(() => {
          this.$message.success('操作成功')
          this.getList()
        })
      }).catch(() => {
        this.$message.info('取消输入')
      })
    },
    handleSelectionChange(val) {
      this.selectionList = val
      const data = []
      this.selectionList.map((item) => {
        data.push(item.id)
      })
      this.ids = data.join(',')
    },
    // 选择时间
    selectChange(tab) {
      this.timeVal = []
      this.tableFrom.page = 1
      this.getList()
      this.getOrderStatusNum()
      // this.getOrderListData();
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e
      this.tableFrom.dateLimit = e ? this.timeVal.join(',') : ''
      this.tableFrom.page = 1
      this.getList()
      this.getOrderStatusNum()
      // this.getOrderListData();
    },
    // 编辑
    edit(row) {
      this.orderId = row.id
      this.editData = {
        orderId: row.id,
        totalPrice: row.totalPrice,
        totalPostage: row.totalPostage,
        payPrice: row.totalMoney,
        payPostage: row.payPostage
        // gainIntegral: row.gainIntegral,
      }
      this.dialogVisible = true
    },
    handlerSubmit(formValue) {
      let data = {
        orderNo: formValue.orderId,
        payPrice: formValue.payPrice
      }
      updatePriceApi(data).then(data => {
        this.$message.success('编辑数据成功')
        this.dialogVisible = false
        this.getList()
      })
    },
    // 列表
    getList() {
      this.listLoading = true
      orderListApi(this.tableFrom).then(res => {
        console.log('订单数据', res)
        this.tableData.data = res.records || []
        this.tableData.total = res.total
        this.listLoading = false
        this.checkedCities = this.$cache.local.has('order_stroge') ? this.$cache.local.getJSON('order_stroge') : this.checkedCities
        console.log(this.tableData.data)
      }).catch(() => {
        this.listLoading = false
      })
    },
    // 数据统计
    getOrderListData() {
      orderListDataApi({ dateLimit: this.tableFrom.dateLimit }).then(res => {
        this.cardLists = [
          { name: '订单数量', count: res.count, color: '#1890FF', class: 'one', icon: 'icondingdan' },
          { name: '订单金额', count: res.amount, color: '#A277FF', class: 'two', icon: 'icondingdanjine' },
          {
            name: '微信支付金额',
            count: res.weChatAmount,
            color: '#EF9C20',
            class: 'three',
            icon: 'iconweixinzhifujine'
          },
          { name: '余额支付金额', count: res.yueAmount, color: '#1BBE6B', class: 'four', icon: 'iconyuezhifujine2' }
        ]
      })
    },
    // 获取各状态数量
    getOrderStatusNum() {
      orderStatusNumApi({ dateLimit: this.tableFrom.dateLimit, type: this.tableFrom.type }).then(res => {
        this.orderChartType = res
      })
    },
    pageChange(page) {
      this.tableFrom.page = page
      this.getList()
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val
      this.getList()
    },
    exports() {
      let data = {
        dateLimit: this.tableFrom.dateLimit,
        orderNo: this.tableFrom.orderNo,
        status: this.tableFrom.status,
        type: this.tableFrom.type
      }
      orderExcelApi(data).then(res => {
        window.open(res.fileName)
      })
    },
    renderHeader(h) {
      return (
        <p>
          <span style="padding-right:5px;">操作</span>
          <i class="el-icon-setting" onClick={() => this.handleAddItem()}></i>
        </p>
      )
    },
    handleAddItem() {
      if (this.card_select_show) {
        this.$set(this, 'card_select_show', false)
      } else if (!this.card_select_show) {
        this.$set(this, 'card_select_show', true)
      }
    },
    handleCheckAllChange(val) {
      this.checkedCities = val ? this.columnData : []
      this.isIndeterminate = false
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length
      this.checkAll = checkedCount === this.columnData.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.columnData.length
    },
    checkSave() {
      this.$modal.loading('正在保存到本地，请稍候...')
      this.$cache.local.setJSON(
        'order_stroge', this.checkedCities
      )
      setTimeout(this.$modal.closeLoading(), 1000)
    },
    //打印小票
    onOrderPrint(data) {
      orderPrint(data.id).then(res => {
        this.$modal.msgSuccess('打印成功')
      }).catch(error => {
        this.$modal.msgError(error.message)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.el-table__body {
  width: 100%;
  table-layout: fixed !important;
}

.demo-table-expand {
  ::v-deeplabel {
    width: 83px !important;
  }
}

.refunding {
  span {
    display: block;
  }
}

.selWidth {
  width: 300px;
}

.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
  font-size: 12px;
}

.el-icon-arrow-down {
  font-size: 12px;
}

.tabBox_tit {
  font-size: 12px !important;
  /*margin: 0 2px 0 10px;*/
  letter-spacing: 1px;
  /*padding: 5px 0;*/
  box-sizing: border-box;
}

.text_overflow {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}

.pup_card {
  width: 200px;
  border-radius: 5px;
  padding: 5px;
  box-sizing: border-box;
  font-size: 12px;
  line-height: 16px;
}

.flex-column {
  display: flex;
  flex-direction: column;
}

.mt20 {
  margin-top: 20px
}

.relative {
  position: relative;
}

.card_abs {
  position: absolute;
  padding-bottom: 15px;
  top: 520px;
  right: 40px;
  width: 200px;
  background: #fff;
  z-index: 99999;
  box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.1);
}

.cell_ht {
  height: 50px;
  padding: 15px 20px;
  box-sizing: border-box;
  border-bottom: 1px solid #eeeeee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.check_cell {
  width: 100%;
  padding: 15px 20px 0;
}

::v-deep .el-checkbox__input.is-checked + .el-checkbox__label {
  color: #606266;
}
</style>
